import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import type { Question } from '@/api/types/Question'
import type { Ref } from 'vue'

export const useQuestionStore = defineStore('question', () => {
  const questions: Ref<Question[]> = ref([{
    description: "mock",
    options: ['mockA', 'mockB', 'mockC'],
    answer: new Set([0]),
    explaination: 'mock explaination',
    choice: new Set([])
  }])

  const total = computed(() => questions.value.length)
  const correct = computed(() => {
    let count = 0
    questions.value.forEach((question) => {
      if(question.choice.size != question.answer.size) {
        return
      }
      for(let x of question.choice) {
        if(!question.answer.has(x)) {
          return
        }
      }
      count++
    })
    return count
  })

  function append(question: Question) {
    questions.value.push(question)
  }

  return { questions, total, correct, append }
})
